//
//  JGValidateLoginController.m
//  JGRider
//
//  Created by 单启志 on 2018/3/2.
//  Copyright © 2018年 ffq. All rights reserved.
//

#import "JGValidateLoginController.h"
#import "JGValidateLoginContentView.h"
#import "JGRegistController.h"//注册
#import "JGLoginApi.h"
#import "JGRootViewHelper.h"
@interface JGValidateLoginController ()<JGValidateLoginContentViewDelegate,YTKChainRequestDelegate>
@property(nonatomic,strong)JGValidateLoginContentView *contentView;
@property(nonatomic,strong)MBProgressHUD *hud;
@end

@implementation JGValidateLoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configSubViews];
}

-(void)configSubViews{

    [self.view addSubview:self.contentView];
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - override
-(UIColor *)lmjNavigationBackgroundColor:(LMJNavigationBar *)navigationBar{

    return [UIColor whiteColor];
}

-(BOOL)lmjNavigationIsHideBottomLine:(LMJNavigationBar *)navigationBar{
    return NO;
}

-(NSMutableAttributedString *)lmjNavigationBarTitle:(LMJNavigationBar *)navigationBar{

   return [NSMutableAttributedString changeTitle:@"验证码登录" color:HEXCOLOR(0x404040)];
}

-(UIImage *)lmjNavigationBarLeftButtonImage:(UIButton *)leftButton navigationBar:(LMJNavigationBar *)navigationBar{
    return [UIImage imageNamed:@"signup_icon_return"];
}

- (UIStatusBarStyle)navUIBaseViewControllerPreferStatusBarStyle:(LMJNavUIBaseViewController *)navUIBaseViewController
{
    return UIStatusBarStyleDefault;
}

#pragma mark - contentView delegate
-(void)contentViewValidateCodeEvent{
    //TODO:向服务器请求验证码
    
}
-(void)contentViewLoginEventWithParams:(NSDictionary *)params{

    [[JGRequestHelper share]requestWithParams:params requestApi:[JGLoginApi class] hudMessage:@"登录中..." view:self.view successBlock:^(id result) {
        NSString *states=result[@"data"][@"state"];
        if ([states isEqualToString:@"11000"]) {
            //登录成功
            NSDictionary *dic= result[@"data"][@"obj"];
            JGLoginResponseModel *model=[JGLoginResponseModel mj_objectWithKeyValues:dic];

            //归档登录成功获取的数据
            [[JGCodingHelper share]loginsuccessDataEncodeWith:model];
            [JGRootViewHelper setTabBarViewController];
        }
    } faileBlock:nil];

//    _hud=[MBProgressHUD showMessage:@"登录中..." ToView:self.view];
//    FQGetSignApi *signApi=[[FQGetSignApi alloc]initWithParams:params];
//    FQChainRequest *chinaReq=[[FQChainRequest alloc]init];
//    [chinaReq addRequest:signApi callback:^(YTKChainRequest * _Nonnull chainRequest, YTKBaseRequest * _Nonnull baseRequest) {
//        FQGetSignApi *api= (FQGetSignApi*)baseRequest;
//        JGLoginApi *loginApi=[[JGLoginApi alloc]initWithSi:[api si] Pa:[api pa]];
//        [chainRequest addRequest:loginApi callback:nil];
//    }];
//    chinaReq.delegate=self;
//    [chinaReq start];

}
-(void)contentViewRegistEvent{
    JGRegistController *vc=[[JGRegistController alloc]init];
    JGpushViewController(vc);
}

//#pragma mark api - delegate
//-(void)chainRequestFinished:(YTKChainRequest *)chainRequest{
//
//    JGLoginApi *api=(JGLoginApi*)chainRequest.requestArray[1];
//
//    NSString *msg=api.responseJSONObject[@"data"][@"msg"];
//    NSString *states=api.responseJSONObject[@"data"][@"state"];
//    if ([states isEqualToString:@"11000"]) {
//        //登录成功
//        NSDictionary *dic= api.responseJSONObject[@"data"][@"obj"];
//        JGLoginResponseModel *model=[JGLoginResponseModel mj_objectWithKeyValues:dic];
//
//        //归档登录成功获取的数据
//        [[JGCodingHelper share]loginsuccessDataEncodeWith:model];
//        [JGRootViewHelper setTabBarViewController];
//    }
//    _hud.label.text=msg;
//    [_hud hideAnimated:YES afterDelay:0.5];
//    NSLog(@"%@",api.responseString);
//}
//-(void)chainRequestFailed:(YTKChainRequest *)chainRequest failedBaseRequest:(YTKBaseRequest *)request{
//
//    _hud.label.text=@"登录失败";
//    [_hud hideAnimated:YES afterDelay:0.5];
//}

#pragma mark -getter
-(JGValidateLoginContentView *)contentView{
    
    if (_contentView==nil) {
        _contentView=[[JGValidateLoginContentView alloc]initWithFrame:CGRectMake(0, self.lmj_navgationBar.height, JGScreenW, JGScreenH-self.lmj_navgationBar.height)];
        _contentView.delegate=self;
    }
    return _contentView;
}

@end
